package user;

import org.PWCrypt;

public class User {
	private static int count=0;
	String name, password;
	int id;

	public User() {
		this.id=count++;
	}
	public User(String name) {
		this.name=name;
		this.id=count++;
	}
	public User(String name, String password) {
		this.name=name;
		this.password=password;
		this.id=count++;
	}
	private User(int id,String name,String password){
		this.id=id;
		this.name=name;
		this.password=password;
	}
	
	//Reconstruct a User from File
	public static User reconstruct(int id, String name, String password) {
		return new User(id,name,password);
	}
	
	public static void failed() {
		count--;
	}
	
	//Setter
	public void setPassword(String pass) {
		this.password=pass;
	}
	public static void setCount(int c) {
		count=c;
	}

	//Getter
	public int getId() {
		return this.id;
	}
	public String getName(){
		return this.name;
	}
	public String getPassword(){
		return this.password;
	}
	public static int getCount() {
		return count;
	}
	
	
	@Override
	public String toString(){
		return new String("User:"+this.name+" ID="+this.id+" PW:"+PWCrypt.scramblePW(this)+" Hash:"+this.hashCode());
	}
	@Override
	public boolean equals(Object obj) {
		if(this==obj)
			return true;
		if(obj==null || this.getClass()!=obj.getClass())
			return false;
		User anotherUser=(User)obj;
		return (this.id==anotherUser.id) && ( this.name==anotherUser.name || (this.name!=null&&this.name.equals(anotherUser.name)) );
	}
	@Override
	public int hashCode() {
		int hash=11,prime=31;
		hash=prime*hash+id;
		hash=prime*hash+(name==null ? 0 : name.hashCode());
		return hash;
	}
}
